<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>16.5.DOM-事件高级-常见事件对象的属性和方法-阻止冒泡事件（重点）</title>
    <style>
        .father {
            position: relative;
            width: 300px;
            height: 300px;
            background-color: red;
            text-align: center;
        }

        .son {
            position: absolute;
            top: 150px;
            left: 150px;
            transform: translate(-100px, -100px);
            width: 200px;
            height: 200px;
            line-height: 200px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div class="father">
        <div class="son">son盒子</div>
    </div>
    <script>
        // 常见事件对象的属性和方法
        // 阻止冒泡 dom 推荐的标准 stopPropagation(); stop 停止 propagation 传播  

        var son = document.querySelector('.son');
        son.addEventListener('click', function (e) {
            alert('son');
            e.stopPropagation();
        }, false);
        var father = document.querySelector('.father');
        father.addEventListener('click', function (e) {
            alert('father');
            e.stopPropagation();
        }, false);
        document.addEventListener('click', function (e) {
            alert('document');
            e.stopPropagation();
        })
        // e.cancelBubble = true; 非标准 cancel 取消 Bubble 泡泡
        if (e && e.stopPropagation) {
            e.stopPropagation();
        } else {
            window.event.cancelBubble = true;
        }
    </script>
</body>

</html>